import { ChangePassword } from '@/domain/entity/ChangePassword';
import axios from '../config/AxiosConfig';
import { ResponsePage } from '../domain/entity/ResponsePage';
import { Result } from '../domain/entity/Result';
import { SystemUser } from '../domain/entity/SystemUser';
import { UserInfoListQuery } from '../domain/query/UserInfoListQuery';

const moduleUrl = "/system/system-user";

const getUserInfoUrl = moduleUrl + "/getUserInfo";
const getUserListUrl = moduleUrl + "/getList";
const getUserListPageUrl = moduleUrl + "/getListPage";
const updateUserUrl = moduleUrl + "/update";
const deleteUserUrl = moduleUrl + "/delete";
const updateDisabledUrl = moduleUrl + "/updateDisabled";
const addUserUrl = moduleUrl + "/add";
const getUserDetailUrl = moduleUrl + "/getDetail";
const resetPasswordUrl = moduleUrl + "/resetPassword";
const changePasswordUrl = moduleUrl + "/changePassword";


export const getUserInfo = function() {
    return axios.get(getUserInfoUrl);
}

export const getDetail = (userId:string) => {
    return axios.get<Result<SystemUser>>(getUserDetailUrl + "/" + userId);
}


export const getList = () => {
    return axios.get(getUserListUrl);
}

export const getListPage = function(query:UserInfoListQuery) {
    return axios.get<Result<ResponsePage<SystemUser>>> (getUserListPageUrl, {
        params: query,
    });
}

export const requestInsert = function(user:SystemUser) {
    return axios.post<Result<SystemUser>> (addUserUrl, user);
}

export const requestUpdate = function(user:SystemUser) {
    return axios.put<Result<SystemUser>> (updateUserUrl, user);
}

export const requestDelete = function(userId:string) {
    return axios.delete<Result<string>>(deleteUserUrl + "/" + userId);
}

export const requestUpdateDisabled = function(userId:string) {
    return axios.put<Result<string>>(updateDisabledUrl + "/" + userId);
}

export const requestResetPassowrd = function(userId:string) {
    return axios.put<Result<string>>(resetPasswordUrl + "/" + userId);
}

export const requestChangePassowrd = function(changePassword:ChangePassword) {
    return axios.post<Result<SystemUser>> (changePasswordUrl, changePassword);
}


